import {Tabs, Button, Space} from 'antd'
import React, {useState, useEffect} from 'react'
import E from 'wangeditor'
import http from '../../../../utils/http'

// 3.编辑商品详情组件
const GoodsDetails = ({setdefaultActiveKey, history, getDate, isEdit}) => {
  const [val, setVal] = useState('')
  let [editor, seteditor] = useState('')
  let [editData, seteditData] = useState({})

  // 编辑状态
  // useEffect(() => {
  //   if (isEdit) {
  //     let editData1 = JSON.parse(sessionStorage.getItem('editData'))
  //     seteditData(editData1)

  //   }
  // }, [])

  // 编辑器
  useEffect(() => {
    editor = new E(document.getElementById('edit'))
    editor.config.height = 565
    editor.create()
    setVal(editor.txt.text(), 222)


  }, [val])


  // 编辑状态改变表单里面的值

  // 保存
  const submit = () => {
    console.log(editor.txt.editor.change.node.innerText)
    sessionStorage.setItem('addGoodsDetails', JSON.stringify(editor.txt.editor.change.node.innerText))
    http({
      url: '/huangyi/addAllGoods',
      method: 'post',
      data: {
        ...JSON.parse(sessionStorage.getItem('addBasicInformation')),
        ...JSON.parse(sessionStorage.getItem('addPriceInventory')),
        information: sessionStorage.getItem('addGoodsDetails'),
        create_time: '2021.8.11',
        sall_num: 0,
        deleted: 0,
      }
    }).then(res => {
      console.log(res)
      history.push('/admin/product/list?state=3')
      getDate()
    })

  }
  // 上一步
  const goAhead = () => {
    setdefaultActiveKey('2')
  }



  return (
    <div className="goodsDetails">
      <div className="tit">编辑商品详情</div>
      <div id="edit">
      </div>
      <Space size="large" className='opeart'>
        <Button type="default" onClick={goAhead}>上一步</Button>
        <Button type="primary" onClick={submit}>保存</Button>
      </Space>
    </div>
  )
}

export default GoodsDetails